class BINOP_SET_VIEW{ETP} < $RO_SET{ETP} |
---|
**** | View of a binary operation between two sets. Handles union, intersection, diff and sym_diff Instead of copying the sets, it merely maintains pointers to the two sets. This view is read-only and *cannot* be used to modify the original sets. Note that it is *not* a value interface. In fact, if the original sets change, this view will automatically change. In some cases this is exactly the behavior you want; in other cases it can be a source of nasty problems. Use carefully.
_ Usage: _____s1:_$SET{INT}_:=_#SET{INT}(|1,2,3,5|); _____s2:_$SET{INT}_:=_#SET{INT}(|1,5,3,9|); _____s_::=_BINOP_SET_VIEW{INT}::create_union(s1,s2); _____#OUT+_s.str; ______--_will_print_out_the_elements_1,2,3,5,9_in_some_arbitrary_order _____s2.delete(9); _____#OUT+s.str; ______--_will_print_out_the_elements_1,2,3,5_in_some_arbitrary_order _ Implementation: _____Maintains_pointers_to_the_two_sets,_primary_and_secondary _____The_space_of_the_final_set_is_broken_down_into: _____Primary_set:_(_______primary_______________)__ _____Seconary_set:_______________(__________secondary_________) _____Result:______(_p_minus_s____(_intersection_)__s_minus_p__) ____ _____The_flags_use_p_minus_s,_use_intersect_and_use_s_minus_p_indicate _____which_part_should_be_used |
$RO_SET{_} | $STR | $CONTAINER{_} | $ELT{_} | $ELT | RO_SET_INCL{_} | COMPARE{_} |
as_array: ARRAY{E} .. Included as as_array |
---|
copy: SAME |
---|
**** | Copy returns a copy of the same type of set |
create(prim: $RO_SET{ETP}, sec: $RO_SET{ETP}, |
---|
create_diff(prim: $RO_SET{ETP},sec: $RO_SET{ETP}): SAME |
---|
create_intersection(prim: $RO_SET{ETP},sec: $RO_SET{ETP}): SAME |
---|
create_sym_diff(prim: $RO_SET{ETP},sec: $RO_SET{ETP}): SAME |
---|
create_union(prim: $RO_SET{ETP},sec: $RO_SET{ETP}): SAME |
---|
diff(s: $RO_SET{E}): SET{E} .. Included as diff |
---|
**** | See the comment for "union" and $RO_SET::diff |
diff_view(s: $RO_SET{E}): $RO_SET{E} .. Included as diff_view |
---|
**** | See the comment for "union_view" |
equals(a:$RO_SET{E}): BOOL .. Included as equals |
---|
**** | Returns 'true' if every element of self is elt_eq to an element in 'a' and vice versa. Neither may be void. |
has(e: ETP): BOOL |
---|
**** | Return true if "e" belongs to this set ph = primary has e sh = secondary has e * indicates a don't care ph sh p-s p in s s-p T T => result is True if * t * T F => result is True if t * * F T => True if * * t F F => result is False |
intersection(s:$RO_SET{E}): SET{E} .. Included as intersection |
---|
**** | See the comment for "union" and $RO_SET::intersection |
intersection_view(s: $RO_SET{E}): $RO_SET{E} .. Included as intersection_view |
---|
**** | See the note for "union_view" |
is_empty: BOOL .. Included as is_empty |
---|
**** | Do not do size=0. Finding size may require iteration through all elements - quite wasteful for just "is_empty" |
is_subset_of(s: $RO_SET{E}): BOOL .. Included as is_subset_of |
---|
**** | Return true if "self" is a subset of "s" |
size: INT .. Included as size |
---|
str: STR .. Included as str |
---|
**** | Prints out a string version of the array of the components that are under $STR |
sym_diff(s: $RO_SET{E}): SET{E} .. Included as sym_diff |
---|
**** | See the comment for "union" and $RO_SET::sym_diff |
sym_diff_view(s: $RO_SET{E}): $RO_SET{E} .. Included as sym_diff_view |
---|
**** | See the comment for "union_view" |
union(s: $RO_SET{E}): SET{E} .. Included as union |
---|
**** | Union is defined by default to create a "view" and then convert that into a SET. Subtypes may redefine this behavior to return a set of type "SAME", without going through a view |
union_view(s: $RO_SET{E}): $RO_SET{E} .. Included as union_view |
---|
**** | Return a read-only "view" of the union of "self" and "s" The resulting view just points to the two component sets and computes its elements on-the-fly, as needed. As a result, this form of union requires almost no additional space but may it may take slightly longer to perform operations |
elt!: ETP |
---|
create_from_internal(s: $RO_SET{E}): SET{E} .. Included as create_from_internal |
---|
**** | Used as an auxilliary routine by the view creation routines. When the return type can be any $RO_SET, then by default a "SET" will be constructed and used |
elt_eq(e1,e2:ETP):BOOL .. Included as elt_eq |
---|
**** | The "less than" relation used in the sorting routines. Compares the object "id" by default. May be redefined in descendants. |
elt_hash(e:ETP):INT .. Included as elt_hash |
---|
**** | A hash value associated with an element. Must have the property that if "elt_eq(e1,e2)" then "elt_hash(e1)=elt_hash(e2)". Can be defined to always return 0, but many routines will then become quadratic. Uses object "id" by default. May be redefined in descendants. |
elt_lt(e1,e2:ETP):BOOL .. Included as elt_lt |
---|
**** | The "less than" relation used in the sorting routines. Compares the object "id" by default. May be redefined in descendants. |
elt_nil: ETP .. Included as elt_nil |
---|
**** | Return the nil value. If the element is under $NIL then return e.nil. Otherwise, return void
_ |
get_set_of_self: SAME .. Included as get_set_of_self |
---|
is_elt_nil(e:ETP):BOOL .. Included as is_elt_nil |
---|
attr primary: $RO_SET{ETP}; |
---|
attr primary: $RO_SET{ETP}; |
---|
attr secondary: $RO_SET{ETP}; |
---|
**** |
attr secondary: $RO_SET{ETP}; |
---|
**** |
attr use_intersect: BOOL; |
---|
**** | Use elements in prim intersect sec |
attr use_intersect: BOOL; |
---|
**** | Use elements in prim intersect sec |
attr use_p_minus_s: BOOL; |
---|
**** | Use elements in prim-sec |
attr use_p_minus_s: BOOL; |
---|
**** | Use elements in prim-sec |
attr use_s_minus_p: BOOL; |
---|
**** | Use elements in sec - prim |
attr use_s_minus_p: BOOL; |
---|
**** | Use elements in sec - prim |